package com.ddzh.web;

import com.ddzh.dto.OrderDto;
import com.ddzh.entity.Result;
import com.ddzh.service.OrderService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/orderController")
public class OrderController {

    @Reference(timeout = 1500,mock ="true" )
    private OrderService orderService;

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发短信业务
     * @param telephone
     * @return
     */
    @GetMapping("/sendSmsCode/{telephone}")
    public Result sendSmsCode(@PathVariable("telephone") String telephone){
        rabbitTemplate.convertAndSend("sms_exchange","sms",telephone);
        return new Result(true);
    }

    /**
     * 单击确定预约时的操作
     * @param orderDto
     * @return
     */
    @PostMapping("/appoOrder")
    public Result appoOrder(@RequestBody OrderDto orderDto){
        //下单操作
        /***
         * 点击提交之后要干什么？
         * 0.验证码校验
         * 1.用户预约校验
         * 2.预约当天是否可以预约校验
         * 3.新增订单
         * 4.维护订单数量
         * 5.新增 / 修改会员信息
         */
        Long aLong = orderService.appoOrder(orderDto);
        if(aLong==1) {
            Result result = new Result(orderDto);
            result.setFlag(false);
            result.setMessage("当前预约火爆,请稍后再试");
            return result;
        }else {
            return new Result(aLong);
        }
    }

    @GetMapping("/getOrderRes/{orderId}")
    public Result getOrderRes(@PathVariable("orderId")Long orderId){
        return new Result(orderService.getOrderRes(orderId));
    }
}
